﻿using System.Collections;
using System.Collections.Generic;
using NetSystem;
using UnityEngine;
using ResourceSystem;
using BehaviorSystem;
using SkillSystem;

public class Tese : MonoBehaviour {
    IMessageTerminal messageTerminal;
    IBehaviorAgent agent;
    

	// Use this for initialization
	void Start () {
        ResourceSystemFacade.Inst.InitSystem();
        BehaviorSystemFacade.Inst.InitBehaviourTick();
        messageTerminal = MessageSystem.MessageSystemFacade.Inst.PopMessageTerimal(this.gameObject);
        messageTerminal.RegisterMessage("Test", (args) => { DebugUtils.LogRedInfo("Test"); });
        //AssetBundleStream abStream = ResourceSystemFacade.Inst.DownLoadResource("Cube 1");
        //abStream.OnLoadFinish += () => { MonoBehaviour.Instantiate((GameObject)abStream.Content); };
        //NetSystemFacade.Inst.DownLoadFile("cube 1.assetbundle.manifest");

        InputSystem.InputSystemFacade.Inst.InitInputListener();

        agent = this.gameObject.AddComponent<BehaviourAgent>();
        agent.RootNode = new BehaviourTree(this.agent);
        SequenceNode sequenceNode = new SequenceNode(agent);
        SelectorNode selectorNode = new SelectorNode(agent);
        ParallelNode parallelNode = new ParallelNode(agent);
        agent.RootNode.ChildrenNodes.Add(parallelNode);

        parallelNode.ChildrenNodes.Add(sequenceNode);
        parallelNode.ChildrenNodes.Add(selectorNode);

        sequenceNode.ChildrenNodes.Add(new LogNode(agent, "Test1"));
        //sequenceNode.ChildrenNodes.Add(new ConditionNode(agent,null));
        sequenceNode.ChildrenNodes.Add(new LogNode(agent, "Test3"));

        //selectorNode.ChildrenNodes.Add(new LogNode(agent, "Test4"));
        selectorNode.ChildrenNodes.Add(new ConditionNode(agent, null));
        selectorNode.ChildrenNodes.Add(new LogNode(agent, "Test5"));

        SkillSystemFacade.Inst.Init();
        SkillData data=SkillSystemFacade.Inst.GetSkillDataByID(1);
        DebugUtils.LogRedInfo(data.Name);
    }
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKey(KeyCode.A))
        {
            MessageSystem.MessageSystemFacade.Inst.SendMessage("Test", null);
        }

	}
}
